﻿using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace Demo
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

        }
        private Point m_BackgroundImageLocation;

        /// <summary>
        /// 获取或者设置背景图片的位置。
        /// </summary>
        public Point BackgroundImageLocation
        {
            get { return m_BackgroundImageLocation; }
            set
            {
                m_BackgroundImageLocation = value;
                this.Refresh();
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            treeView1.SelectedNode = treeView1.Nodes[0].FirstNode;
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            switch (e.Node.Text)
            {
                case "图表":
                    panelMain.Controls.Clear();
                    Chart chart = new Chart();
                    chart.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(chart);
                    break;
                case "公式":
                    //panelMain.
                    panelMain.Controls.Clear();
                    Formula formula = new Formula();
                    formula.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(formula);
                    break;
                //case "兼容Excel":
                //    panelMain.Controls.Clear();
                //    ExcelLikeGrouping excel = new ExcelLikeGrouping();
                //    excel.Dock = DockStyle.Fill;
                //    panelMain.Controls.Add(excel);
                //    break;
                case "移动多行或多列":
                    panelMain.Controls.Clear();
                    MoveRowCol moveRowCol = new MoveRowCol();
                    moveRowCol.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(moveRowCol);
                    break;
                case "图形":
                    panelMain.Controls.Clear();
                    shapes shape=new shapes();
                    shape.Dock=DockStyle.Fill;
                    panelMain.Controls.Add(shape);
                    break;
                case"分组和多行列脚":
                    panelMain.Controls.Clear();
                    columnGroupFooter groupFooter = new columnGroupFooter();
                    groupFooter.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(groupFooter);
                    break;
                case "自动合并":
                    panelMain.Controls.Clear();
                    Merging mergin = new Merging();
                    mergin.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(mergin);
                    break;
                case "冻结行列":
                    panelMain.Controls.Clear();
                    freezeRowsCols freeze = new freezeRowsCols();
                    freeze.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(freeze);
                    break;
                case "过滤":
                    panelMain.Controls.Clear();
                    Filtering filter = new Filtering();
                    filter.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(filter);
                    break;
                case "排序":
                    panelMain.Controls.Clear();
                    Sort sort = new Sort();
                    sort.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(sort);
                        break;
                case "Outlook样式分组":
                        panelMain.Controls.Clear();
                        Grouping group = new Grouping();
                        group.Dock = DockStyle.Fill;
                        panelMain.Controls.Add(group);
                    break;
                case "Excel样式分组":
                    panelMain.Controls.Clear();
                    ExcelLikeGrouping excelLikeGrouping = new ExcelLikeGrouping();
                    excelLikeGrouping.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(excelLikeGrouping);
                    break;
                case "级联":
                    panelMain.Controls.Clear();
                    hierarchy myHierarchy = new hierarchy();
                    myHierarchy.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(myHierarchy);
                    break;
                case "行预览":
                    panelMain.Controls.Clear();
                    previewRow preRow = new previewRow();
                    preRow.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(preRow);
                    break;
                case "标题和子标题":
                    panelMain.Controls.Clear();
                    titleSubTitle title = new titleSubTitle();
                    title.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(title);
                    break;
                case "多表头":
                    panelMain.Controls.Clear();
                    MultipleHearders mulHeaders = new MultipleHearders();
                    mulHeaders.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(mulHeaders);
                    break;
                case "多视图及缩放":
                    panelMain.Controls.Clear();
                    Zoom zoom = new Zoom();
                    zoom.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(zoom);
                    break;
                case "撤销和重做":
                    panelMain.Controls.Clear();
                    Undo undo = new Undo();
                    undo.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(undo);
                    break;
                case "打印到PDF":
                    panelMain.Controls.Clear();
                    PDFExport pdfExport = new PDFExport();
                    pdfExport.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(pdfExport);
                    break;
                case "Spread皮肤":
                    panelMain.Controls.Clear();
                    SpreadSkins skins = new SpreadSkins();
                    skins.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(skins);
                    break;
                case "Excel导入导出":
                    panelMain.Controls.Clear();
                    ExcelImportandExport excelImportAndExport = new ExcelImportandExport();
                    excelImportAndExport.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(excelImportAndExport);
                    break;
                case "单元格类型":
                    panelMain.Controls.Clear();
                    CellType cellType = new CellType();
                    cellType.Dock = DockStyle.Fill;
                    panelMain.Controls.Add(cellType);
                    break;
                default:
                    break;
            }
        }

        private void setMainPanel(DemoBaseUserControl ucontrol)
        {
            ucontrol.Dock = DockStyle.Fill;
            this.panelMain.Controls.Add(ucontrol);
            if (this.panelMain.Controls.Count > 1)
            {
                this.panelMain.Controls.RemoveAt(0);
            }
        }

        private void MainForm_Paint(object sender, PaintEventArgs e)
        {
            Color[] colors = new Color[] { Color.FromArgb(11, 121, 120), Color.White };
            float[] rate = new float[] { 0f, 0.7f };

            using (System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), colors[0], colors[1], LinearGradientMode.Vertical))
            {
                e.Graphics.FillRectangle(brush, new Rectangle(0, 0, this.Width, this.Height));
            }
        }

        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {
            Bitmap backgroundImage = Demo.Properties.Resources.background;
            if (backgroundImage != null)
                e.Graphics.DrawImage(backgroundImage, e.ClipRectangle.Width - backgroundImage.Width, 0,
                    backgroundImage.Width, backgroundImage.Height);

        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("http://www.gcpowertools.com.cn/products/SpNet_overview.htm");
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("http://www.gcpowertools.com.cn/products/SpNet_overview.htm");
        }
    }
}
